package com.neuedu.yyzx.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.neuedu.yyzx.config.CommonResult;
import com.neuedu.yyzx.entity.UserCare;
import com.neuedu.yyzx.entity.UsersList;
import com.neuedu.yyzx.service.IUsersListService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 第7组....
 * @since 2021-04-28
 */
@RestController
@RequestMapping("//usersList")
public class UsersListController {

    @Autowired
    IUsersListService usersListService;

    @RequestMapping("/list")
    public CommonResult list(@RequestParam(defaultValue = "1") Integer pageNo, @RequestParam(defaultValue = "10") Integer pageSize, UsersList usersList) {
        QueryWrapper queryWrapper = new QueryWrapper();
//        queryWrapper.eq("name",0);
        if (usersList != null && StringUtils.isNotEmpty(usersList.getName())) {
            queryWrapper.like("name", usersList.getName());
        }

        return CommonResult.success(usersListService.page(new Page<>(pageNo, pageSize), queryWrapper));

    }
    @RequestMapping(value = "/usercarelist",method = RequestMethod.GET)
        public Map<String,Object> allArea(){
        Map<String,Object> modelMap=new HashMap<>();
        List<UserCare> userCareList=usersListService.getUserCareList();
        modelMap.put("userCareList",userCareList);
        return modelMap;
    }



    @RequestMapping("/add")
    CommonResult add(UsersList usersList){
        return CommonResult.success(usersListService.saveOrUpdate(usersList));
    }

    @RequestMapping("/getById")
    CommonResult getById(Integer id){
        return CommonResult.success(usersListService.getById(id));
    }
}


